home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TIMING.SWG / 0010_Controling DOS Timer.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  2KB  |  59 lines

  1. {
  2. DAVID DAHL
  3.  
  4. I never posted it as a Unit.  I just posted a couple routines to set the
  5. timer.  They're actually a part of another, larger project I've been working
  6. on to play digitized Sound out of several different output devices.  When I
  7. was asked if it were possible to speed up the tick and still have Dos's timer
  8. Function behave normally, I threw them into a Unit and wrote the Program you
  9. quoted from to illustrate how it would be done.  Here are the timer routines
  10. as a Unit:
  11.  
  12. The routines perform no error checking on input values, so be careful
  13. with them.  The Procedure Set8253Channel should never have a
  14. channel value of more than 2 since the 8253 only has 3 channels
  15. (0 - 2).
  16. }
  17.  
  18. Unit C8253;
  19.  
  20. (* PUBLIC DOMAIN *)
  21.  
  22. Interface
  23.  
  24. Procedure SetPlaySpeed(Speed : LongInt);
  25. Procedure SetDefaultTimerSpeed;
  26. Procedure Set8253Channel(ChannelNumber : Byte; ProgramValue  : Word);
  27.  
  28. Implementation
  29.  
  30. Const
  31.   C8253ModeControl   = $43;
  32.   C8253OperatingFreq = 1193180;
  33.   C8253Channel : Array [0..2] of Byte = ($40, $41, $42);
  34.  
  35. {=[ 8253 Timer Programming Routines ]=====================================}
  36. Procedure Set8253Channel(ChannelNumber : Byte; ProgramValue  : Word);
  37. begin
  38.   Port[C8253ModeControl] := 54 or (ChannelNumber SHL 6); { XX110110 }
  39.   Port[C8253Channel[ChannelNumber]] := Lo(ProgramValue);
  40.   Port[C8253Channel[ChannelNumber]] := Hi(ProgramValue);
  41. end;
  42. {-[ Set Clock Channel 0 (INT 8, IRQ 0) To Input Speed ]-------------------}
  43. Procedure SetPlaySpeed (Speed : LongInt);
  44. Var
  45.   ProgramValue : Word;
  46. begin
  47.   ProgramValue := C8253OperatingFreq div Speed;
  48.   Set8253Channel(0, ProgramValue);
  49. end;
  50. {-[ Set Clock Channel 0 Back To 18.2 Default Value ]----------------------}
  51. Procedure SetDefaultTimerSpeed;
  52. begin
  53.   Set8253Channel (0, 0);
  54. end;
  55.  
  56. end.
  57.  
  58.  
  59.